import { fetchCors } from '../../common';
import { ApiResponse, Resource, Storefront } from '../types';
import { getAuthToken } from './auth';

export * from './album';
export * from './auth';

export async function getStorefronts(): Promise<Resource<Storefront>[]> {
	const res = await fetchCors('https://api.music.apple.com/v1/storefronts', {
		headers: {
			'Origin': 'https://music.apple.com',
			'Referer': 'https://music.apple.com/',
			'Authorization': `Bearer ${await getAuthToken()}`
		}
	});

	const body = await res.json<ApiResponse<Storefront>>();
	return body.data;
}
